package handler

import (
	"context"
	"github.com/golang/protobuf/ptypes/wrappers"
	"io/ioutil"
	"os"
	"path/filepath"
)

type ConfigurationServiceHandler struct{}

func (c *ConfigurationServiceHandler) Load(ctx context.Context, req *wrappers.StringValue, resp *wrappers.BytesValue) error {

	var b, err = c.loadJsonFile(req.Value)

	resp.Value = b
	return err
}

func (c *ConfigurationServiceHandler) loadJsonFile(name string) ([]byte, error) {

	dir := filepath.Dir(os.Args[0])
	return ioutil.ReadFile(dir + "/json/" + name + ".json")
}
